package com.chris.libs.base.x.mvpp.activity;

import android.os.Bundle;

import androidx.lifecycle.LifecycleObserver;

import com.chris.libs.base.x.mvpp.R;

/**
 * @author Chris Chan
 * on 2019/7/8 10:25
 * use for: mvp模式封装
 */
public abstract class BaseMvppActivity extends BaseInjectActivity {
    protected LifecycleObserver observer;

    @Override
    public void init(Bundle savedInstanceState) {
        super.init(savedInstanceState);
        doProxy();
    }
    /**
     * 托管
     */
    public abstract void doProxy();

    @Override
    public void afterStartActivity() {
        overridePendingTransition(R.anim.bts_anim_act_side_right_in, R.anim.bts_anim_act_side_left_out);
    }

    /**
     * 如果这个方法影响到向前和向后的切换，可以重写
     */
    @Override
    public void afterFinish() {
        overridePendingTransition(R.anim.bts_anim_act_side_left_in, R.anim.bts_anim_act_side_right_out);
    }

    protected void addObserver(LifecycleObserver observer) {
        getLifecycle().addObserver(observer);
    }

    @Override
    protected void onDestroy() {
        if (null != this.observer) {
            getLifecycle().removeObserver(this.observer);
        }
        super.onDestroy();
    }
}
